from PyQt5.QtCore import QThread, pyqtSignal
from util.update_encryption import update_ivs
from util.rebuild_nativlibs import run_gradle_rebuild

from Config import AppConfig


class BuildThread(QThread):
    # 定义信号，用于向主线程传递信息
    log_signal = pyqtSignal(str)  # 发送日志信息
    finished_signal = pyqtSignal(bool)  # 发送构建完成状态

    def __init__(self, project_path):
        super().__init__()
        self.project_path = project_path

    def run(self):
        try:
            # 执行构建
            self.log_signal.emit("开始构建项目...")
            success = run_gradle_rebuild(self.project_path)

            if success:
                self.log_signal.emit("构建成功完成！")
            else:
                self.log_signal.emit("构建失败！")

            self.finished_signal.emit(success)

        except Exception as e:
            self.log_signal.emit(f"执行过程中发生异常: {str(e)}")
            self.finished_signal.emit(False)
